package zjh.msg.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import zjh.msg.entity.Msg;
import zjh.msg.entity.MsgVo;

public interface MsgMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(Msg record);

    Msg selectByPrimaryKey(Integer id);

    List<Msg> selectAll();

    int updateByPrimaryKey(Msg record);

    @Select("select * from msg where reply_id is null order by create_time DESC")
    @Results({
            @Result(property = "id", column = "id", id = true),
            @Result(property = "nickname", column = "nickname"),
            @Result(property = "qq", column = "qq"),
            @Result(property = "email", column = "email"),
            @Result(property = "text", column = "text"),
            @Result(property = "replyId", column = "reply_id"),
            @Result(property = "createTime", column = "create_time"),
            @Result(property = "replyList",
                    column = "id",
                    javaType = List.class,
                    many = @Many(select = "zjh.msg.mapper.MsgMapper.selectReplyById")
            )
    })
    List<MsgVo> pageList();

    @Select("select * from msg where reply_id = #{id}")
    List<MsgVo> selectReplyById(Integer id);
}